/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxinline.manager.pesquisar;

import br.com.foxinline.modelo.Sala;
import br.com.foxinline.servico.SalaServico;
import br.com.foxinline.utilitario.Msg;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ViewScoped
@ManagedBean
public class ManagerPesquisarSala {

    @EJB
    SalaServico salaServico;
    private Sala salaPesquisar;
    private Sala salaEditar;
    private Sala salaVisualizar;
    private Sala salaDelete;
    private List<Sala> salas;
    private String eSala;
    private String vSala;

    @PostConstruct
    public void init() {
        salaPesquisar = new Sala();

        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        eSala = params.get("eSala");
        vSala = params.get("vSala");
        paramPost();
    }

    public void paramPost() {
        if (eSala != null) {
            salaEditar = salaServico.pesquisar(Long.parseLong(eSala));
        }
        if (vSala != null) {
            salaVisualizar = salaServico.pesquisar(Long.parseLong(vSala));
        }
    }

    public void pesquisar() {
        salas = salaServico.pesquisar(salaPesquisar);
    }

    public void deletar() {
        salaServico.deletar(salaDelete);
        salas.remove(salaDelete); 
    }
    
      public void atualizar() {
        try {
            salaServico.atualizar(salaEditar);
            Msg.messagemInfo(Msg.SuccessFull);
          
        } catch (Exception e) {
            e.printStackTrace();
            Msg.messagemError(Msg.Failure);
        }
    }

    public Sala getSalaPesquisar() {
        return salaPesquisar;
    }

    public void setSalaPesquisar(Sala salaPesquisar) {
        this.salaPesquisar = salaPesquisar;
    }

    public Sala getSalaEditar() {
        return salaEditar;
    }

    public void setSalaEditar(Sala salaEditar) {
        this.salaEditar = salaEditar;
    }

    public Sala getSalaVisualizar() {
        return salaVisualizar;
    }

    public void setSalaVisualizar(Sala salaVisualizar) {
        this.salaVisualizar = salaVisualizar;
    }

    public List<Sala> getSalas() {
        return salas;
    }

    public void setSalas(List<Sala> salas) {
        this.salas = salas;
    }

    public Sala getSalaDelete() {
        return salaDelete;
    }

    public void setSalaDelete(Sala salaDelete) {
        this.salaDelete = salaDelete;
    }
}
